var tableData = {
	url : ctp + "/payrollController/payrollSearch.shtml?workerId=" + workerId + "&beginTime=" + beginTime,
	propertys : [ "NAME","JOBNO","GROUPNAME","SALARY","CHARGETYPE","UNITPAY","PAYFORM","SHOULD_GIVE","REAL_GIVE"],
	opers : false,
	checkBox:["REC_ID",false],
	doInput : ["REC_ID", "REAL_GIVE"],
	startLoad : function() {
		getListData(this);
	}
};
function searchData(curr) {
	setTagAndValue("form1", "curr", curr);
	setTagAndValue("form1","SUNNADA_PAGE_SIZE",100); 
	tableData.startLoad();
}
$(document).ready(function() {
	$("#applyTime").val(new Date().Format("yyyy-MM-dd hh:mm:ss"));
	$("#beginDate").val(beginTime);
	searchData();
});

function payrollAudit(){
	if(workerId == "" || workerId == null){
		jalert("你未选择发放工资的员工，请选择！");
		return;
	}
	var workerIds = workerId.split(",");
	var data = '[';
	for(var i = 0; i < workerIds.length; i++){
		var realPay = $("#REAL_GIVE" + workerIds[i]).val();
		if(realPay == ""){
			jalert("存在员工应发工资为空的情况，请确认！");
			return;
		}else{
			var reg=/^((\d{1,3}(,\d{3})*)|(\d+))(\.\d{2})?$/ ;  
			if(!reg.test(realPay)){    
				jalert("你输入的员工应发工资格式不正确，请确认！");
				return;
			}
		}
		data += '{"workerId":"' + workerIds[i] + '","realPay":"' + realPay + '"},';
	}
	data = data.substring(0,data.length - 1) + ']';
	
	$.ajax({ 
	 	url: ctp + "/payrollController/saveRealPay.shtml",
	 	data: {"data": data,"beginTime": beginTime},
		type : 'POST',
		success : function(result) {
			if(result == ''){
				var applyCode = getTimeBusiflow();
				
				$.ajax({ 
				 	url: ctp + "/payrollController/payrollToAudit.shtml",
				 	data: {"recIds": workerId,"beginTime": beginTime,"applyCode":applyCode},
					type : 'POST',
					success : function(result) {
						if(result == ''){
							parent.searchData();
							parent.promptInfo();
							var attendance_index = parent.layui.layer.getFrameIndex(window.name);
							parent.layui.layer.close(attendance_index);
						}else{
							jalert(result);
						}
					}
				});
			}else{
				jalert(result);
			}
		}
	});
}

function back(){
	location.href = ctp + "/payrollController/payroll.shtml";
}
